package com.aiphoto.upload.controller;

import com.aiphoto.upload.util.AliyunOSSUtil;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/*
10 1、首先创建FileReader对象
11 2、将FileReader传递给BufferedReader
12 3、采用BufferedReader的readLine()方法和read()方法来读取文件内容
13 4、最后一定要的finally语句中关闭BufferedReader15  */
public class UploadTest {
    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedReader br2 = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\FIS\\v6.500\\path_next.txt"), "GB2312"));
            // 第一种读取文件方式
            //System.out.println("Reading the file using readLine() method: ");
            String contentLine;
            Map map = new HashMap();
            while ((contentLine = br.readLine()) != null) {
                //            contentLine = br.readLine();
                System.out.println("内容:"+contentLine);
                System.out.println("长度:"+contentLine.length());
                String s =contentLine.substring(0,6);
                //读取每一行，并输出
                System.out.println("s:"+s.length());
                System.out.println("s长度:"+s);
                if(s.equals("[value")){
                    //System.out.println("错误!");
                }else {
                    //System.out.println(">>>>>>>>>>>>>>>>>>>>>>");
                    String str1=contentLine.substring(0, contentLine.indexOf("="));
                    //System.out.println("str1:"+str1);
                    String str2=contentLine.substring(str1.length()+1, contentLine.length());
                    //System.out.println("str2:"+str2);
                    map.put(str1,str2);
                    //System.out.println(map);
//                    if (str1.equals("path")){
//                        File file = new File(str2);
//                        String Host = "AIPhoto";
//                        String uploadUrl = AliyunOSSUtil.upload(file, Host);
//                        map.put(str1,uploadUrl);
//                    }
                    if (str1.equals("time")){
                        //System.out.println(str1);
                        long l = Long.parseLong(str2);
                        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");//初始化Formatter的转换格式
                        String hms = formatter.format(l);
                        map.put(str1,hms);
                    }


                }
            }
            System.out.println(map);




//            File file = new File("C:\\Users\\DYF\\Desktop\\背景图片\\232.jpg");
//            String Host = "AIPhoto";
//            String uploadUrl = AliyunOSSUtil.upload(file, Host);
//            System.out.println("uploadUrl:"+uploadUrl);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
                if (br2 != null) {
                    br2.close();
                }
            } catch (IOException e) {
                System.out.println("Error in closing the BufferedReader");
            }
        }
    }

}